export default abstract class UIItem {
  public visible = true
  private x = 0
  private y = 0
  private w = 0
  private h = 0

  public get top() {
    return this.y
  }

  public get left() {
    return this.x
  }

  public get width() {
    return this.w
  }

  public get height() {
    return this.h
  }

  public setGeometry(x: number, y: number, w: number, h: number) {
    this.x = x
    this.y = y
    this.w = w
    this.h = h
  }

  public draw(ctx: CanvasRenderingContext2D) {
    if (!this.visible) {
      return
    }
    ctx.save()
    ctx.translate(this.x, this.y)
    this.onDraw(ctx)
    ctx.restore()
  }

  protected abstract onDraw(ctx: CanvasRenderingContext2D): void

  protected drawBg(ctx: CanvasRenderingContext2D, color: string) {
    ctx.fillStyle = color
    ctx.fillRect(0, 0, this.width, this.height)
  }
}
